package com.dianrui.operation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dianrui.operation.R;
import com.dianrui.operation.bean.Area;
import com.wx.wheelview.adapter.BaseWheelAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AreaAdapter extends BaseWheelAdapter<Area> {
    private Context context;
    private List<Area> list;

    public AreaAdapter(Context context, List<Area> list) {
        this.context = context;
        this.list = list;
    }

    public void refresh(List<Area> list) {
        this.list = list;
        this.notifyDataSetChanged();
    }

    @Override
    protected View bindView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_area_name, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        if (list.size()>0) {
            Area area = list.get(position);
            holder.areaName.setText(area.area_name);

        }
        return convertView;
    }


    class ViewHolder {
        @BindView(R.id.area_name)
        TextView areaName;
        @BindView(R.id.layout_area)
        LinearLayout layoutArea;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
